package com.epoint.service;

import java.sql.Date;
import java.util.List;
import java.util.UUID;

import com.epoint.dao.QuoteInfoDao;
import com.epoint.entity.QuoteInfo;

/**
 * @Description 
 * @author ylc
 */
public class QuoteInfoService {

	QuoteInfoDao quoteInfoDao = new QuoteInfoDao();
	/**
	 * 获取报价信息列表
	 * @param valueOf
	 * @param valueOf2pageIndex
	 * @param sortField
	 * @param sortOrder
	 * @return
	 */
	public List<QuoteInfo> getQuoteList(int pageIndex, int pageSize, String sortField, String sortOrder) {
		return quoteInfoDao.getQuoteList(pageIndex,pageSize,sortField,sortOrder);
	}

	/**
	 * 获取报价列表总数
	 * @return
	 */
	public int getQuoteListCount() {
		return quoteInfoDao.getQuoteListCount();

	}

	/**
	 * 根据supplierId删除报价信息,同时更新产品信息表中的信息
	 * @param supplierId
	 * @param productId
	 * @return
	 */
	public int deleteQuoteInfoById(String supplierId,String productId) {
		return quoteInfoDao.deleteQuoteInfoById(supplierId,productId);
	}

	/**
	 * 添加报价信息
	 * @param quoteInfo
	 * @return
	 */
	public int addQuoteInfo(QuoteInfo quoteInfo) {
		// 填入默认编号
		quoteInfo.setSupplierId(UUID.randomUUID().toString());
		// 填入当前时间
		Date date = new Date(System.currentTimeMillis());
		quoteInfo.setCreateTime(date);
		
		// 同一个供应商每天最多报价2次，如有超过则弹框提示“该产品今日报价次数达到2次，无法继续报价”
		if(isQuoteCount(quoteInfo.getSupplierName()) >= 2) {
			return 2;
		}else {
			return quoteInfoDao.addQuoteInfo(quoteInfo);
		}
	}
	/**
	 * 判断当前供应商报价次数
	 * @return
	 */
	public int isQuoteCount(String supplierName) {
		return quoteInfoDao.isQuoteCount(supplierName);
	}

}
